ADD_FORCING

ADD_FORCING

function add_forcing(obj,f,varargin)
        

This function is used to add external forcing to the DynamicalSystem object. The various input formats are explained in the tutorial on setting up a dynamical system.

if ~isfield(f, 'data') % new format
    switch obj.order
        case 1
            nn = size(f,1);
            Kappas = varargin{1};
            data(1).kappa = Kappas(1);
            data(2).kappa = Kappas(2);
            data(1).F_n_k(1).coeffs = f(:,1);
            data(1).F_n_k(1).ind    = zeros(1,nn);
            data(2).F_n_k(1).coeffs = f(:,2);
            data(2).F_n_k(1).ind    = zeros(1,nn);
            f_ext.data = data;
        case 2
            nn = size(f,1);
            Kappas = varargin{1};
            data(1).kappa = Kappas(1);
            data(2).kappa = Kappas(2);
            data(1).f_n_k(1).coeffs = f(:,1);
            data(1).f_n_k(1).ind    = zeros(1,nn);
            data(2).f_n_k(1).coeffs = f(:,2);
            data(2).f_n_k(1).ind    = zeros(1,nn);
            f_ext.data = data;
    end

    if numel(varargin)>1
        f_ext.epsilon = varargin{2};
    else
        f_ext.epsilon = 1;
    end
else
    f_ext = f;
end

switch obj.order

    case 1
        obj.Fext.data = f_ext.data;

        if isfield(f_ext,'epsilon')
            obj.Fext.epsilon = f_ext.epsilon;

        elseif nargin == 3
            obj.Fext.epsilon = varargin{1};

        else
            obj.Fext.epsilon = 1;

        end

    case 2
        obj.fext.data = f_ext.data;

        if isfield(f_ext,'epsilon')
            obj.fext.epsilon = f_ext.epsilon;

        elseif nargin == 3
            obj.fext.epsilon = varargin{1};

        else
            obj.fext.epsilon = 1;

        end
end
        
end